package queries;

import java.util.ArrayList;

import common.CheckBoxObject;

import entitys.Area;
import entitys.Category;
import entitys.Customer;
import entitys.CustomerSale;
import entitys.LoginUser;
import entitys.MarketingPattern;
import entitys.Product;
import entitys.ProductInType;
import entitys.Request;
import entitys.Type;
import enums.Command;
import enums.Result;

public class QuerySelector {
	
	
	public static Object handleRequest(Request req,java.sql.Connection conn) {
		
		if(req.getCommand().equals(Command.ADD_PRODUCT))
		{
			return AddProductQuery.exe((Product) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.ADD_CATEGORY))
		{
			return AddCategoryQuery.exe((Category) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.GET_MARKETING_SALES))
		{
			return GetMarketingSalesQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.GET_ADDRESSED_CLIENTS_AMOUNT_BY_MARKETING_SALE))
		{
			return GetAddressedClientsAmountByMarketingSaleQuery.exe(conn, (Integer) req.getEntity());
		}
		else if(req.getCommand().equals(Command.GET_REVIEW))
		{
			return GetReviews.exe(conn, (Integer) req.getEntity());
		}
		else if(req.getCommand().equals(Command.GET_SOLD_AMOUNT))
		{
			return GetSoldAmount.exe(conn, (Integer) req.getEntity());
		}
		else if(req.getCommand().equals(Command.ASSOCIATE_PRODUCT))
		{
			return AssociateProductQuery.exe((ProductInType) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.EDIT_CATEGORY))
		{
			return EditCategoryQuery.exe((Category) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.DELETE_CATEGORY))
		{
			return DeleteCategoryQuery.exe((Category) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.ADD_TYPE))
		{
			return AddTypeQuery.exe((Type) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.EDIT_TYPE))
		{
			return EditTypeQuery.exe((Type) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.DELETE_TYPE))
		{
			return DeleteTypeQuery.exe((Type) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.ADD_AREA))
		{
			return AddAreaQuery.exe((Area) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.DELETE_AREA))
		{
			return DeleteAreaQuery.exe((Area) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.GET_AREAS))
		{
			return GetAreasListQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.GET_AREAS_WITH_PREFIX))
		{
			return GetAreasListQuery.exe(conn,(Area)req.getEntity());
		}
		else if(req.getCommand().equals(Command.DELETE_ASSOCIATION))
		{
			return DeleteAssociationQuery.exe((ProductInType) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.ADD_CLIENT))
		{
			return AddClientQuery.exe((Customer) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.ADD_CLIENT_CATEGORIES))
		{
			return AddClientQuery.exeCat((ArrayList<String>) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.UPDATE_CLIENT))
		{
			return UpdateClientQuery.exe((Customer) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.GET_CLIENTS))
		{
			return GetCustomerListQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.GET_EXTERNAL_CLIENTS))
		{
			return GetCustomerListQuery.exeExternal(conn);
		}
		else if(req.getCommand().equals(Command.GET_CLIENTS_WITH_PERMIT))
		{
			return GetCustomersWithPermissionQuery.exe(req,conn);
		}
		else if(req.getCommand().equals(Command.GET_PRODUCTS))
		{
			if(req.getEntity()!=null)
				return GetProductsListQuery.exe(conn,(String)req.getEntity().toString());
			
			return GetProductsListQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.GET_TRIO))
		{
			return GetTrioListQuery.exe(conn);
		}
		
		else if(req.getCommand().equals(Command.GET_PRODUCT_CATEGORIES))
		{
			return GetProductCategoryListQuery.exe(conn);
		}
		
		else if(req.getCommand().equals(Command.GET_PRODUCT_TYPES))
		{
			return GetProductTypesListQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.GET_PRODUCT_TYPES_BY_CATEGORY))
		{
			return GetProductTypesListByCategoryQuery.exe(conn, (Category)req.getEntity());
		}
		
		else if(req.getCommand().equals(Command.GET_PRODUCT_TYPES_WITH_PREFIX))
		{
			return GetProductTypesListQuery.exe(conn,(Type)req.getEntity());
		}
		
		else if(req.getCommand().equals(Command.GET_PRODUCT_CATEGORIES_WITH_PREFIX))
		{
			return GetProductCategoryListQuery.exe(conn,(Category)req.getEntity());
		}
		
		else if(req.getCommand().equals(Command.DELETE_PRODUCT))
		{
			return DeleteProductQuery.exe(req,conn);
		}
	
		else if(req.getCommand().equals(Command.LOGIN))
		{
			return GetUsersQuery.exe((LoginUser) req.getEntity(),conn);
		}
		
		else if(req.getCommand().equals(Command.LOGOUT))
		{
			return LogoutQuery.exe((LoginUser) req.getEntity(),conn);
		}
		
		else if(req.getCommand().equals(Command.SET_LAST_ADDRESSED))
		{
			return SetLastAddressedQuery.exe((Integer) req.getEntity(),conn);
		}
		
		else if(req.getCommand().equals(Command.CHANGE_REFFER_PERMISSION))
		{
			return ChangeRefferPermissionQuery.exe((Customer) req.getEntity(),conn);
		}
		
		else if(req.getCommand().equals(Command.ADD_ADDRESS_SALE))
		{
			return AddAddressSaleQuery.exe(req,conn);
		}
		
		else if(req.getCommand().equals(Command.WEEKLY_ANALSYS))
		{
			return WeeklyAnalysisQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.ADD_MARKETING_PATTERN))
		{
			return SetMarketingPatternQuery.exe((MarketingPattern) req.getEntity(),conn);
		}
		else if(req.getCommand().equals(Command.GET_SALE_PERSONS))
		{
			return GetSalesPersonQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.GET_MARKETING_PATTERNS))
		{
			return GetMarketingPatternQuery.exe(conn);
		}

		else if(req.getCommand().equals(Command.GET_MARKETING_SALES_BY_ID))
		{
			return GetMarketingSalesByEmpQuery.exe(req,conn);
		}
		
		else if(req.getCommand().equals(Command.GET_PATERNED_CLIENTS))
		{
			if(req.getEntity()!=null)
				return GetPatternedClientsQuery.exe(conn,(String)req.getEntity().toString());
			
			return GetPatternedClientsQuery.exe(conn);
		}
		
		else if(req.getCommand().equals(Command.GET_PRODUCTS_BY_MARKETING_SALE))
		{
				return GetProductsByMarketingSaleQuery.exe(conn,(String)req.getEntity().toString());
		}
		
		else if(req.getCommand().equals(Command.ADD_NEW_SALE))
		{
			return CreateSaleQuery.exe(conn,(ArrayList<ArrayList<CheckBoxObject>>)req.getEntity(),(String)req.getEntity2());
		}
		else if(req.getCommand().equals(Command.GET_SALES))
		{
			return GetSales.exe(conn);
		}
		
		else if(req.getCommand().equals(Command.CUSTOMER_CHARACTERIZATION_REPORT))
		{
			return GetCustomerCharacterizationReportQuery.exe(conn);
		}
		else if(req.getCommand().equals(Command.UPDATE_SALE))
		{
			return UpdateSale.exe((String) req.getEntity(),conn);
		}
		else
		{
			System.out.println("Unknown Command");
			return Result.ERROR;
		}
					
		
	}
}
